package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.HelpFirefighter;
import com.ruoyi.help.service.IHelpFirefighterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消防员Controller
 * 
 * @author ruoyi
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/help/firefighter")
public class HelpFirefighterController extends BaseController
{
    @Autowired
    private IHelpFirefighterService helpFirefighterService;

    /**
     * 查询消防员列表
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpFirefighter helpFirefighter)
    {
        startPage();
        List<HelpFirefighter> list = helpFirefighterService.selectHelpFirefighterList(helpFirefighter);
        return getDataTable(list);
    }

    /**
     * 导出消防员列表
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:export')")
    @Log(title = "消防员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpFirefighter helpFirefighter)
    {
        List<HelpFirefighter> list = helpFirefighterService.selectHelpFirefighterList(helpFirefighter);
        ExcelUtil<HelpFirefighter> util = new ExcelUtil<HelpFirefighter>(HelpFirefighter.class);
        util.exportExcel(response, list, "消防员数据");
    }

    /**
     * 获取消防员详细信息
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return success(helpFirefighterService.selectHelpFirefighterByUId(uId));
    }

    /**
     * 新增消防员
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:add')")
    @Log(title = "消防员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HelpFirefighter helpFirefighter)
    {
        return toAjax(helpFirefighterService.insertHelpFirefighter(helpFirefighter));
    }

    /**
     * 修改消防员
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:edit')")
    @Log(title = "消防员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HelpFirefighter helpFirefighter)
    {
        return toAjax(helpFirefighterService.updateHelpFirefighter(helpFirefighter));
    }

    /**
     * 删除消防员
     */
    @PreAuthorize("@ss.hasPermi('help:firefighter:remove')")
    @Log(title = "消防员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(helpFirefighterService.deleteHelpFirefighterByUIds(uIds));
    }
}
